package com.tdkj.action.backstage.website;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.tdkj.action.BaseAction;
import com.tdkj.model.user.BeanUser;
import com.tdkj.model.website.BeanProtocol;
import com.tdkj.model.website.BeanProtocolDetail;
import com.tdkj.model.website.BeanQqservice;
import com.tdkj.service.website.IBeanQqService;
public class QqServiceAction  extends BaseAction{
	private long id;
	private String qq;
	private String username;
	private Long userid;
	private List<BeanQqservice> qqs=new ArrayList<BeanQqservice>();
	private IBeanQqService qqService;
	private String[] ids;
	public String deleteAll() {
		if (null != ids) {
			for (String idtemp : ids) {
				this.getBaseService().delete(Long.parseLong(idtemp), BeanQqservice.class);
			}
		}
		return findAll();
	}
	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getQq() {
		return qq;
	}
	public void setQq(String qq) {
		this.qq = qq;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public Long getUserid() {
		return userid;
	}
	public void setUserid(Long userid) {
		this.userid = userid;
	}
	public List<BeanQqservice> getQqs() {
		return qqs;
	}
	public void setQqs(List<BeanQqservice> qqs) {
		this.qqs = qqs;
	}
	@Resource
	public void setQqService(IBeanQqService qqService) {
		this.qqService = qqService;
	}
	//获取qq列表
	public String findAll(){
		qqs=qqService.findAll(BeanQqservice.class);
		if(qqs.size()==0)appendObj(20);
		Criteria criteria = this.createCriteria(BeanQqservice.class);
		criteria.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "qqServiceAction!findAll.action", 10);
		return "findAll";
	}
	//获取添加界面
	public String getEditPage(){
		BeanQqservice bean=qqService.findById(this.getId(), BeanQqservice.class);
		this.setId(bean.getId());
		this.setQq(bean.getQq());
		this.setUsername(bean.getUsername());
		this.setUserid(bean.getUserid());
		return "editPage";
	}
	//获取添加界面
	public String getAddPage(){
		return "addPage";
	}
	//删除QQ
	public String deleteQqService(){
		BeanQqservice bean=new BeanQqservice();
		bean.setId(this.getId());
		qqService.delete(bean);
		return findAll();
	}
	//获取添加界面
	public String addQqService(){
		BeanUser u=qqService.findById(2l, BeanUser.class);
		BeanQqservice bean=new BeanQqservice();
		bean.setUserid(this.getUserid());
		bean.setUsername(this.getUsername());
		bean.setCreatetime(new Timestamp(System.currentTimeMillis()));
		bean.setQq(this.getQq());
		qqService.save(bean);
		return findAll();
	}
	//获取添加界面
	public String editQqService(){
		BeanQqservice bean=qqService.findById(2l, BeanQqservice.class);
		bean.setQq(this.getQq());
		qqService.save(bean);
		return findAll();
	}
	private  void appendObj(int num) {
		// TODO Auto-generated method stub
		BeanQqservice bean=null;
		BeanUser u=qqService.findById(2l, BeanUser.class);
		for(int i=0;i<num;i++){
			bean=new BeanQqservice();
			bean.setUserid(new Long(i));
			bean.setUsername("张大"+i);
			bean.setQq("23456789"+i);
			bean.setCreatetime(new Timestamp(System.currentTimeMillis()));
			qqService.save(bean);
		}
	}
	public String findOnlineService(){
		Criteria criteria = this.createCriteria(BeanQqservice.class);
		criteria.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "qqServiceAction!findOnlineService.action", 10);
		return "f_index";
	}
}
